package cn.jinjimi.app.custom.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.jinjimi.base.util.AndroidUtils;
import cn.jinjimi.app.R;
import cn.jinjimi.app.store.entity.custom.ContactInfo;
import cn.jinjimi.app.main.dialog.CustomAddPhoneTypeDialog;

/**
 * Created by Roy
 * 客户资料电话item
 * Date: 16/6/12
 */
public class CustomInfoPhoneView extends LinearLayout {
    private Context mContext = null;
    private TextView tvTitle;
    private TextView tvPhone;
    private ImageView imgPhone;

    public CustomInfoPhoneView(Context context) {
        this(context, null);
    }

    public CustomInfoPhoneView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomInfoPhoneView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.view_custom_info_phone_layout, this);
        mContext = context;
        initView();
    }

    private void initView() {
        tvTitle = (TextView) findViewById(R.id.tv_phone_title);
        tvPhone = (TextView) findViewById(R.id.tv_phone);
        imgPhone = (ImageView) findViewById(R.id.img_phone_visible);
    }

    public void setPhone(ContactInfo phone) {
        tvTitle.setText(CustomAddPhoneTypeDialog.getTypeNameById(phone.getType()));
        tvPhone.setText(phone.getValue());
        imgPhone.setVisibility(VISIBLE);
        imgPhone.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                AndroidUtils.call(mContext, tvPhone.getText().toString().trim());
            }
        });
    }

    public void setEmptyPhone() {
        tvTitle.setText(mContext.getString(R.string.csutom_contact_title));
        imgPhone.setVisibility(GONE);
    }
}
